//
//  WorkerResumeSettingViewController.m
//  Btpin
//
//  Created by Vic on 2019/4/19.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "WorkerResumeSettingViewController.h"

@interface WorkerResumeSettingViewController ()
{
    UISwitch *contactSwitch;
    UISwitch *notSuitableSwith;
}
@end

@implementation WorkerResumeSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"简历设置";
    
    [self initUI];
}
- (void)initUI {
    self.view.backgroundColor = THEMECOLOR_OF_GRAY;
    
    UIView *workerBgView = [UIToolsControl initViewWithFrame:CGRectMake(0, 10*Scale, WIDTH, 70*Scale) backgroundColor:COLOR_OF_WHITE];
    [self.view addSubview:workerBgView];
    UIImageView *imgView = [UIToolsControl initImageViewWithFrame:CGRectMake(LeftSpace, 15*Scale, 40*Scale, 40*Scale) imageName:@"header_bg"];
    imgView.contentMode = UIViewContentModeScaleAspectFill;
    imgView.layer.cornerRadius = 20*Scale;
    imgView.layer.masksToBounds = YES;
    [workerBgView addSubview:imgView];
    if (self.user_headerImg.length) {
        [imgView sd_setImageWithURL:[NSURL URLWithString:self.user_headerImg]];
    }
    UILabel *nameLbl = [UIToolsControl initLabelWithFrame:CGRectMake(EndX(imgView)+20*Scale, 0, 200, ViewHeight(workerBgView)) text:(self.user_name&&self.user_name.length)?self.user_name:@"" textColor:THEMECOLOR_OF_TEXT_666666 font:Font_14];
    [workerBgView addSubview:nameLbl];
    
    UIView *contactSwitchBgView = [UIToolsControl initViewWithFrame:CGRectMake(0, EndY(workerBgView)+5*Scale, WIDTH, 45*Scale) backgroundColor:COLOR_OF_WHITE];
    [self.view addSubview:contactSwitchBgView];
    UILabel *rejectLbl = [UIToolsControl initLabelWithFrame:CGRectMake(LeftSpace, 0, 300, ViewHeight(contactSwitchBgView)) text:@"待沟通" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    [contactSwitchBgView addSubview:rejectLbl];
    contactSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(WIDTH-75*Scale, 3*Scale, 45*Scale, 22*Scale)];
    contactSwitch.thumbTintColor = COLOR_OF_WHITE;
    contactSwitch.onTintColor = THEMECOLOR_OF_ORANGE;
    [contactSwitch addTarget:self action:@selector(contactSwitchTap:) forControlEvents:UIControlEventValueChanged];
    contactSwitch.transform = CGAffineTransformMakeScale(0.75, 0.75);
    [contactSwitchBgView addSubview:contactSwitch];
    
    UIView *notSuitableSwithBgView = [UIToolsControl initViewWithFrame:CGRectMake(0, EndY(contactSwitchBgView)+5*Scale, WIDTH, 45*Scale) backgroundColor:COLOR_OF_WHITE];
    [self.view addSubview:notSuitableSwithBgView];
    UILabel *notSuitableLbl = [UIToolsControl initLabelWithFrame:CGRectMake(LeftSpace, 0, 300, ViewHeight(contactSwitchBgView)) text:@"不合适" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    [notSuitableSwithBgView addSubview:notSuitableLbl];
    notSuitableSwith = [[UISwitch alloc] initWithFrame:CGRectMake(WIDTH-75*Scale, 3*Scale, 45*Scale, 22*Scale)];
    notSuitableSwith.thumbTintColor = COLOR_OF_WHITE;
    notSuitableSwith.onTintColor = THEMECOLOR_OF_ORANGE;
    [notSuitableSwith addTarget:self action:@selector(notSuitableSwithTap:) forControlEvents:UIControlEventValueChanged];
    notSuitableSwith.transform = CGAffineTransformMakeScale(0.75, 0.75);
    [notSuitableSwithBgView addSubview:notSuitableSwith];
    
    
    UIButton *deleteBtn = [UIToolsControl initButtonWithFrame:CGRectMake(40*Scale, EndY(notSuitableSwithBgView)+110*Scale, WIDTH-80*Scale, 46*Scale) imageName:nil target:self action:@selector(deleteBtnTap) title:@"删除" titleColor:COLOR_OF_WHITE];
    deleteBtn.layer.cornerRadius = 23*Scale;
    deleteBtn.layer.masksToBounds = YES;
    deleteBtn.backgroundColor = THEMECOLOR_OF_RED;
    deleteBtn.titleLabel.font = Font(Font_18);
    [self.view addSubview:deleteBtn];
}
- (void)contactSwitchTap:(UISwitch *)switchButton {
    NSLog(@"switchBtn:%@", contactSwitch.on?@"YES":@"NO");
    [self upDateOp_type:@"1" op_val:(contactSwitch.on?@"1":@"0")];
}
- (void)notSuitableSwithTap:(UISwitch *)switchButton {
    NSLog(@"switchBtn:%@", notSuitableSwith.on?@"YES":@"NO");
    [self upDateOp_type:@"2" op_val:(notSuitableSwith.on?@"1":@"0")];
}
- (void)deleteBtnTap {
    NSLog(@"删除");
    [self upDateOp_type:@"3" op_val:@""];
}
- (void)upDateOp_type:(NSString *)op_type op_val:(NSString *)op_val {
    SVPHUDShow;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    dic = [UIToolsControl getPublicParameter];
    [dic setObject:self.toudi_id forKey:@"id"];
    [dic setObject:op_type forKey:@"op_type"];
    [dic setObject:op_val forKey:@"op_val"];
    
    [BaseNetManager requestWithMethod:POST path:Company_ManagerResume_URL params:dic successBlock:^(NSDictionary * _Nonnull responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            SVPHUDSuccess(responseObject[@"msg"]);
            if ([op_type isEqualToString:@"3"]) {
                [self performSelector:@selector(delayClick) withObject:nil afterDelay:0.5];
            }
        } else {
            SVPHUDError(responseObject[@"msg"]);
        }
    } failurBlock:^(NSError * _Nonnull error) {
        SVPHUDError(NetErrorAlertText);
    }];
}
- (void)delayClick {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
